package com.kws.system.controller.contractManagement;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kws.common.log.annotation.Log;
import com.kws.common.log.enums.BusinessType;
import com.kws.system.domain.contractManagementDao.Rq.CreateContractTemplateRq;
import com.kws.system.domain.contractManagementDao.info.QueryContractTemplateInfo;
import com.kws.system.service.contractTemplateService.ContractTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.kws.common.core.domain.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <b>ContractTemplateController</b>
 *
 * @description: ContractTemplateController <br>
 * @date: 2024/11/18 13:50 <br>
 * @author: lhm <br>
 * @version: 1.0 <br>
 */

@Api(tags = "平台合同模板管理")
@RestController
public class ContractTemplateController {
    private Logger logger = LoggerFactory.getLogger(ContractTemplateController.class);

    @Autowired
    private ContractTemplateService contractTemplateService;

    @ApiOperation("分页查询平台合同模板列表")
    @GetMapping("/query/contractTemplate/page")
    public R<Page<QueryContractTemplateInfo>> queryContractTemplatePage(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                                                        @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
                                                                        @RequestParam(required = false) String name,
                                                                        @RequestParam(required = false) Integer type){
        R<Page<QueryContractTemplateInfo>> result = contractTemplateService.queryContractTemplatePage(pageNum,pageSize,name,type);
        return result;
    }

    @ApiOperation("新增平台系统模板信息")
    @Log(title = "新增平台系统模板信息", businessType = BusinessType.INSERT)
    @PostMapping("/create/contractTemplate")
    public R createContractTemplate(@RequestBody CreateContractTemplateRq rq){
        boolean status = contractTemplateService.createContractTemplate(rq);
        return R.ok(status);
    }


    @ApiOperation("根据模板ID查询合同列表")
    @GetMapping("/query/templateFile/byId")
    public R queryTemplateFileById(@RequestParam Long id){
        List<String> fileUrlList =  contractTemplateService.queryTemplateFileById(id);
        return R.ok(fileUrlList);
    }

    @ApiOperation("根据ID删除平台系统模板")
    @Log(title = "删除平台系统模板", businessType = BusinessType.DELETE)
    @GetMapping("/delete/contractTemplate/byId")
    public R deleteContractTemplateById(@RequestParam Long id){
        boolean status = contractTemplateService.deleteContractTemplateById(id);
        return R.ok(status);
    }
}
